/*
 * Copyright 2011-2012 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.sabayframework.cluster.impl.kryo;

import org.sabayframework.cluster.ComputerId;

/**
 * Contains data that gets transferred over the network.
 * */
public final class NetworkPacket {
	
	private int activityId;
	private RequestType type;
	/**
	 * List of symbolic names of OSGi bundles that are required to process data. 
	 * Server must load and start these bundles before
	 * deserializing data.
	 * See documentation on Require-Bundle header of OSGi bundle.
	 * */
	private String requireBundle;
	/**
	 * List of packages that must be imported in order to process data.
	 * Packages must be imported before deserializing data.
	 * See documentation on Import-Package header of OSGi bundle. 
	 * */
	private String importPackage;
	private byte[] data;
	private byte[] activity;
	private ComputerId remoteId;
	
	NetworkPacket(){}
	
	public NetworkPacket(int activityId, RequestType type, byte[] data) {
		super();
		this.activityId = activityId;
		this.type = type;
		this.data = data;
	}

	public int getActivityId() {
		return activityId;
	}

	public RequestType getType() {
		return type;
	}

	public String getRequireBundle() {
		return requireBundle;
	}

	public void setRequireBundle(String requireBundle) {
		this.requireBundle = requireBundle;
	}

	public String getImportPackage() {
		return importPackage;
	}

	public void setImportPackage(String importPackage) {
		this.importPackage = importPackage;
	}

	public void setData(byte[] data) {
		this.data = data;
	}

	public byte[] getData() {
		return data;
	}

	public byte[] getActivity() {
		return activity;
	}

	public void setActivity(byte[] activity) {
		this.activity = activity;
	}

	/**
	 * Returns id of a computer that sent this request. 
	 * */
	public ComputerId getRemoteId() {
		return remoteId;
	}

	public void setRemoteId(ComputerId remoteId) {
		this.remoteId = remoteId;
	}

	@Override
	public String toString() {
		return "NetworkPacket [client=" + remoteId + ", activityId="
				+ activityId + ", type=" + type + ", requireBundle="
				+ requireBundle + ", importPackage=" + importPackage 
				+ ", data.length=" + (data==null? 0:data.length) + "]";
	}
	
}
